package im.starchat.chat.activity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;

import butterknife.ButterKnife;
import butterknife.InjectView;
import im.qcloud.Module.Vod;
import im.qcloud.QcloudApiModuleCenter;
import im.starchat.chat.R;
import im.starchat.chat.XLApplication;
import im.starchat.chat.activity.profile.ContributionActivity;
import im.starchat.chat.adapter.ChatMsgListAdapter;
import im.starchat.chat.adapter.MemberListAdapter;
import im.starchat.chat.dialog.CommentDialogFragment;
import im.starchat.chat.dialog.HostDialogFragment;
import im.starchat.chat.dialog.MemberDialogFragment;
import im.starchat.chat.dialog.ShareRoomDialogFragment;
import im.starchat.chat.rest.model.CommentBean;
import im.starchat.chat.rest.model.MemberInfo;
import im.starchat.chat.rest.model.PlaySetBean;
import im.starchat.chat.rest.model.RoomBean;
import im.starchat.chat.rest.model.UserBean;
import im.starchat.chat.rest.model.api.NullResponse;
import im.starchat.chat.rest.model.api.VideoRecordResponse;
import im.starchat.chat.rest.model.api.ZhiboUserListResponse;
import im.starchat.chat.utils.GsonUtil;
import im.starchat.chat.utils.PreferencesStorageUtil;
import im.starchat.chat.utils.UserUtils;
import im.starchat.chat.utils.Util;
import im.starchat.chat.view.CircularImageButton;
import im.starchat.chat.view.DanMuView;
import im.starchat.chat.view.HorizontalListView;
import im.starchat.chat.view.PlayBackVideoView;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by liuchao on 3/16/16.
 */
public class PlayBackActivity extends BaseActivity implements View.OnClickListener, MediaPlayer.OnCompletionListener {

    @InjectView(R.id.player)
    PlayBackVideoView mVideoView;
    @InjectView(R.id.bottom_layout)
    FrameLayout mBottomLayout;
    @InjectView(R.id.qav_topbar_hangup)
    ImageView mBackBtn;
    @InjectView(R.id.host_head)
    CircularImageButton hostHead;
    @InjectView(R.id.user_count)
    TextView mUserCount;
    @InjectView(R.id.member_list_layout)
    HorizontalListView mMemberListLayout;
    @InjectView(R.id.im_msg_items)
    ListView mListViewMsgItems;
    @InjectView(R.id.close)
    View mCloseBtn;
    @InjectView(R.id.populator_num)
    TextView mPopulatorNum;
    @InjectView(R.id.mediacontroller_seekbar)
    SeekBar mSeekBar;
    @InjectView(R.id.pause_play_btn)
    ImageView mPlayBtn;
    @InjectView(R.id.outside_share_btn)
    ImageView mShareBtn;
    @InjectView(R.id.populator_layout)
    LinearLayout mPopulatorLayout;
    @InjectView(R.id.gift_top)
    RelativeLayout mGiftTop;
    @InjectView(R.id.gift_bottom)
    RelativeLayout mGiftBottom;
    @InjectView(R.id.live_label)
    TextView mLiveLabel;

    List<CommentBean> mOriCommentList = new ArrayList<>();
    List<CommentBean> mCommentList;
    ChatMsgListAdapter mChatMsgListAdapter;

    VideoRecordResponse mResponse;
    RoomBean mRoomBean;
    MemberInfo hostMember;
    ArrayList<MemberInfo> mMemberList = new ArrayList<>(), mNormalMemberList;


    public static final String FLAG_FILE_ID = "file_id";
    public static final String FLAG_ROOM_ID = "room_id";
    public static final String FLAG_TENCENT_VIDEO_URL = "video_url";
    private String mRoomId = "";
    private String mTencentVideoUrl = "";
    private String mFileId;

    @InjectView(R.id.black_place)
    View mBlackPlace;
    @InjectView(R.id.tanmu)
    DanMuView mDanmuView;

    private static final int MSG_PLAY = 0x1;
    private static final int UPDAT_MEMBER = 2;
    private static final int SHOW_PROGRESS = 3;

    private int page=1;
    private int perPage=20;

//    List<VideoInfo> videos=new ArrayList<VideoInfo>();

    private MemberListAdapter mMemberListAdapter = new MemberListAdapter(PlayBackActivity.this, new MemberListAdapter.MemberListCallBack() {
        @Override
        public void onMemberClick(MemberInfo memberInfo) {
            MemberDialogFragment memberDialogFragment = MemberDialogFragment.newInstance(memberInfo);
            memberDialogFragment.show(getSupportFragmentManager().beginTransaction(), "show_member");
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_playback);
        ButterKnife.inject(this);

        mBlackPlace.setVisibility(View.INVISIBLE);
        mBottomLayout.setVisibility(View.INVISIBLE);
        mMemberListLayout.setAdapter(mMemberListAdapter);
        mDanmuView.setVisibility(View.INVISIBLE);
        mGiftTop.setVisibility(View.INVISIBLE);
        mGiftBottom.setVisibility(View.INVISIBLE);

        mBackBtn.setOnClickListener(this);
        mCloseBtn.setOnClickListener(this);
        mPlayBtn.setOnClickListener(this);
        mShareBtn.setOnClickListener(this);
        mPopulatorLayout.setOnClickListener(this);

        mLiveLabel.setText("回放");

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        Intent intent = getIntent();
        if (intent != null) {
            mFileId = intent.getStringExtra(FLAG_FILE_ID);
            mRoomId = intent.getStringExtra(FLAG_ROOM_ID);
            mTencentVideoUrl = intent.getStringExtra(FLAG_TENCENT_VIDEO_URL);

            if (TextUtils.isEmpty(mTencentVideoUrl) && TextUtils.isEmpty(mFileId)) {
                toast("历史文件为空", Toast.LENGTH_SHORT);
                finish();
            }
//            toast("mFileId--->" + mFileId, Toast.LENGTH_SHORT);
        }
        XLApplication.getInstance().getRestClient().enterRoom(mRoomId + "", UserUtils.getUserInstance().getNickname(), new Callback<NullResponse>() {
            public void success(NullResponse nullResponse, Response response) {

            }

            public void failure(RetrofitError error) {
            }
        });
        getRoomInfo();
        getMemberInfo();
        mListViewMsgItems.setVisibility(View.VISIBLE);
        if (Integer.parseInt(Build.VERSION.SDK) >= 9) {
            mListViewMsgItems.setOverScrollMode(View.OVER_SCROLL_NEVER);
        }
        mSeekBar.setEnabled(true);
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            }

            public void onStartTrackingTouch(SeekBar seekBar) {

                List list = new ArrayList();
                list.addAll(mCommentList);
                list.addAll(mOriCommentList);
                mOriCommentList = list;
                mCommentList.clear();
                int seconds = mVideoView.getCurrentPosition() / 1000;
                Iterator<CommentBean> iterator = mOriCommentList.iterator();
                while (iterator.hasNext()) {
                    CommentBean bean = iterator.next();
                    if (bean.getSeconds_from_start_at() <= seconds) {
                        mCommentList.add(bean);
                        iterator.remove();
                    }
                }
                mChatMsgListAdapter.refresCommentList(mCommentList);
                mListViewMsgItems.setSelection(mCommentList.size() - 1);
                if (mOriCommentList.size() > 0) {
                    mHandler.postDelayed(mLoadCommentRunnable, 1000);
                }
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                int msec = mVideoView.getDuration() * mSeekBar.getProgress() / 1000;
                mVideoView.seekTo(msec);
                int progress = mVideoView.getCurrentPosition()*1000*1000/mVideoView.getDuration();
                mSeekBar.setProgress(progress);
            }
        });

        if (!TextUtils.isEmpty(mTencentVideoUrl)) {
//            VideoInfo vinfo=new VideoInfo();
//            vinfo.description = "标清";
//            vinfo.type = VideoInfo.VideoType.MP4;
//            vinfo.url = mTencentVideoUrl;
//            videos.add(vinfo);
//            mPlayer.play(videos);

            mVideoView.setVideoPath(mTencentVideoUrl);
            showProgressDialog();
            mVideoView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
//                    mp.setLooping(true);
                    dismissProgressDialog();
                    mp.start();
                }
            });
            mVideoView.setOnCompletionListener(this);
            mHandler.sendEmptyMessage(SHOW_PROGRESS);

        } else {
            showProgressDialog();
        /* 如果是循环调用下面举例的接口，需要从此处开始你的循环语句。切记！ */
            new Thread(new Runnable() {
                @Override
                public void run() {
                    TreeMap<String, Object> config = new TreeMap<String, Object>();
                    config.put("SecretId", "AKIDIiuUVCro0n5MpZiNrvaGhwDHQRCL43ik");
                    config.put("SecretKey", "GHQO14eaqnXgbjVbcvxQWENlnNnGvubi");
        /* 请求方法类型 POST、GET */
                    config.put("RequestMethod", "GET");
		/* 区域参数，可选: gz:广州; sh:上海; hk:香港; ca:北美;等。 */
                    config.put("DefaultRegion", "gz");

		/*
		 * 你将要使用接口所在的模块，可以从 官网->云api文档->XXXX接口->接口描述->域名
		 * 中获取，比如域名：cvm.api.qcloud.com，module就是 new Cvm()。
		 */
		/*
		 * 示例：DescribeInstances
		 * 的api文档地址：http://www.qcloud.com/wiki/v2/DescribeInstances
		 */
                    QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Vod(),
                            config);

                    TreeMap<String, Object> getFileInfoparams = new TreeMap<String, Object>();
		/* 将需要输入的参数都放入 params 里面，必选参数是必填的。 */
		/* DescribeInstances 接口的部分可选参数如下 */
                    getFileInfoparams.put("vid", mFileId);//"hhhh_2016-03-16-10-19-");
                    String result = null;
                    try {
			/* call 方法正式向指定的接口名发送请求，并把请求参数params传入，返回即是接口的请求结果。 */
                        result = module.call("DescribeRecordPlayInfo", getFileInfoparams);
                        mResponse = GsonUtil.fromJson(result, VideoRecordResponse.class);
                        System.out.println("PlayBackActivity--->mResponse--->" + result);
                        if (mResponse != null && mResponse.getFileSet() != null && mResponse.getFileSet().size() > 0) {

                            for (PlaySetBean playSetBean : mResponse.getFileSet().get(0).getPlaySet()) {
//                            VideoInfo vinfo=new VideoInfo();
//                            vinfo.description="标清";
//                            vinfo.type=VideoInfo.VideoType.MP4;
//                            vinfo.url=playSetBean.getUrl();
//                            videos.add(vinfo);
                                mTencentVideoUrl = playSetBean.getUrl();
                                System.out.println("PlayBackActivity--->add--->" + playSetBean.getUrl());

                            }

                            mHandler.sendEmptyMessage(MSG_PLAY);

                        }

//                    JSONObject json_result = new JSONObject(result);
//                    System.out.println("PlayBackActivity--->" + json_result);
                    } catch (Exception e) {
                        dismissProgressDialog();
                        System.out.println("error..." + e.getMessage());
                    }


//
//                TreeMap<String, Object> params = new TreeMap<String, Object>();
//		/* 将需要输入的参数都放入 params 里面，必选参数是必填的。 */
//		/* DescribeInstances 接口的部分可选参数如下 */
//                params.put("fileName", mFileId);//"hhhh_2016-03-16-10-19-");
//                params.put("pageNo", 0);
//                params.put("pageSize", 3);
//
//		/* generateUrl方法生成请求串,可用于调试使用 */
//                //System.out.println(module.generateUrl("DescribeInstances", params));
//                String result = null;
//                try {
//			/* call 方法正式向指定的接口名发送请求，并把请求参数params传入，返回即是接口的请求结果。 */
//                    result = module.call("DescribeVodPlayInfo", params);
//                    mResponse = GsonUtil.fromJson(result, VideoPlayResponse.class);
//                    System.out.println("PlayBackActivity--->mResponse--->" + result);
//                    if(mResponse != null && mResponse.getFileSet()!= null && mResponse.getFileSet().size() > 0){
//
//                        for(PlaySetBean playSetBean : mResponse.getFileSet().get(0).getPlaySet()){
//                            VideoInfo vinfo=new VideoInfo();
//                            vinfo.description="标清";
//                            vinfo.type=VideoInfo.VideoType.MP4;
//                            vinfo.url=playSetBean.getUrl();
//                            videos.add(vinfo);
//                            System.out.println("PlayBackActivity--->add--->" + playSetBean.getUrl());
//
//                        }
//
//                        mHandler.sendEmptyMessage(MSG_PLAY);
//
//                    }
//
////                    JSONObject json_result = new JSONObject(result);
////                    System.out.println("PlayBackActivity--->" + json_result);
//                } catch (Exception e) {
//                    System.out.println("error..." + e.getMessage());
//                }
                }
            }).start();
        }


    }


    private long setProgress() {
        if (mVideoView == null)
            return 0;

        long position = mVideoView.getCurrentPosition();
        long duration = mVideoView.getDuration();
//        System.out.println("position--->" + position);
//        System.out.println("duration--->" + duration);
        if (mSeekBar != null) {
            if (duration > 0) {
                long pos = 1000L * position / duration;
                mSeekBar.setProgress((int) pos);
            }
        }

        return position;
    }

    public void loadmore() {
//        //TODO cc getmore
//        toast("more", 1);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.close:
            case R.id.qav_topbar_hangup:
                finish();
                break;
            case R.id.pause_play_btn:
                if (mVideoView != null) {
                    if (mVideoView.isPlaying()) {
                        mVideoView.pause();
                    } else {
                        mVideoView.start();
                    }
                }
                break;
            case R.id.populator_layout:
                if (hostMember != null) {
                    Intent popularIntent = new Intent();
                    popularIntent.setClass(PlayBackActivity.this, ContributionActivity.class);
                    popularIntent.putExtra(ContributionActivity.FLAG_USER_ID, hostMember.getUserPhone());
                    startActivity(popularIntent);
                }

                break;
            case R.id.outside_share_btn:
                System.out.println("mRoomBean" + (mRoomBean == null));
                if (mRoomBean != null) {
                    final ShareRoomDialogFragment shareRoomDialogFragment = ShareRoomDialogFragment.newInstance(mRoomBean);
                    shareRoomDialogFragment.show(getSupportFragmentManager().beginTransaction(), "share_huibo");
                }
                break;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHandler.removeMessages(SHOW_PROGRESS);
    }

    //    private void updatePausePlay() {
//        if (mRoot == null || mPauseButton == null)
//            return;
//
//        if (mPlayer.isPlaying())
//            mPauseButton.setImageResource(R.drawable.media_controller_pause_button);
//        else
//            mPauseButton.setImageResource(R.drawable.media_controller_play_button);
//    }

    private Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(android.os.Message msg) {
            long pos;
            switch (msg.what) {
                case MSG_PLAY:
                    dismissProgressDialog();
//                    mPlayer.play(videos);
                    mVideoView.setVideoPath(mTencentVideoUrl);
                    mVideoView.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
                    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
//                            mp.setLooping(true);
                            mp.start();
                            mHandler.sendEmptyMessage(SHOW_PROGRESS);
                        }
                    });
                    break;
                case UPDAT_MEMBER:
                    updateMemberView();
//                    mChatMsgListAdapter.refresh(hostMember);
                    break;
                case SHOW_PROGRESS:
                    setProgress();
                    updatePausePlay();
                    mHandler.sendEmptyMessageDelayed(SHOW_PROGRESS, 200);
                    break;
                default:
                    break;
            }
            return false;
        }
    });

    @Override
    public void onCompletion(MediaPlayer mp) {
        mPlayBtn.setImageResource(R.drawable.videoplayer_icon_play);
    }

    private void updatePausePlay() {

        if (mVideoView.isPlaying())
            mPlayBtn.setImageResource(R.drawable.videoplayer_icon_stop);
        else
            mPlayBtn.setImageResource(R.drawable.videoplayer_icon_play);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if(mPlayer != null){
//            mPlayer.release();
//        }
        mHandler.removeCallbacks(mLoadCommentRunnable);
    }

    private void getChatEntityList() {
        XLApplication.getInstance().getRestClient().getRoomComments(mRoomId, new Callback<CommentBean[]>() {
            @Override
            public void success(CommentBean[] commentBeans, Response response) {
                if (commentBeans != null && commentBeans.length > 0) {
                    for (int num = 0; num < commentBeans.length; num++) {
                        mOriCommentList.add(commentBeans[num]);
                    }
//                    System.out.println("mOriCommentList--->" + mOriCommentList.size() );
//                    mOriCommentList = Arrays.asList(commentBeans);
                    mCommentList = new ArrayList<CommentBean>();
                    int seconds = mVideoView.getCurrentPosition() / 1000;
                    Iterator<CommentBean> iterator = mOriCommentList.iterator();
                    while (iterator.hasNext()) {
                        CommentBean bean = iterator.next();
                        if (bean.getSeconds_from_start_at() <= seconds) {
                            mCommentList.add(bean);
                            iterator.remove();
                        }
                    }
                    mChatMsgListAdapter = ChatMsgListAdapter.createInstanceFromComment(PlayBackActivity.this,
                            mCommentList, mMemberList, hostMember, new ChatMsgListAdapter.MemberListCallBack() {
                                @Override
                                public void onCommentClick(CommentBean commentBean) {
                                    CommentDialogFragment mCommentDialogFragment = CommentDialogFragment.newInstance(commentBean);
                                    mCommentDialogFragment.show(getSupportFragmentManager().beginTransaction(), "show_member");
                                }

                                @Override
                                public void onUserInfoClick(String userId) {

                                }
                            });
                    mListViewMsgItems.setVisibility(View.VISIBLE);

                    View view = LayoutInflater.from(PlayBackActivity.this).inflate(R.layout.view_msg_list_header, null, false);
                    mListViewMsgItems.addHeaderView(view);
                    mListViewMsgItems.setAdapter(mChatMsgListAdapter);
                    mListViewMsgItems.setSelection(mCommentList.size() - 1);
                    mHandler.postDelayed(mLoadCommentRunnable, 1000);
                }
            }

            @Override
            public void failure(RetrofitError error) {

            }
        });
    }

    private Runnable mLoadCommentRunnable = new Runnable() {
        @Override
        public void run() {
            int seconds = mVideoView.getCurrentPosition() / 1000;
            Iterator<CommentBean> iterator = mOriCommentList.iterator();
            while (iterator.hasNext()) {
                CommentBean bean = iterator.next();
                if (bean.getSeconds_from_start_at() <= seconds) {
                    mCommentList.add(bean);
                    iterator.remove();
                }
            }
            mChatMsgListAdapter.refresCommentList(mCommentList);
            mListViewMsgItems.setSelection(mCommentList.size() - 1);
            if (mOriCommentList.size() > 0) {
                mHandler.postDelayed(this, 1000);
            }
        }
    };


    private void getRoomInfo() {
        XLApplication.getInstance().getRestClient().getFeedInfo(mRoomId + "", new Callback<RoomBean>() {
            @Override
            public void success(RoomBean roomBean, Response response) {
                if (roomBean != null) {
                    mRoomBean = roomBean;
                    if (roomBean.getUser() != null) {
                        hostMember = new MemberInfo(roomBean.getUser().getId(),
                                roomBean.getUser().getNickname(),
                                roomBean.getUser().getAvatar());
                    }

                    if (hostMember != null && mMemberList != null && mMemberList.size() > 0) {
                        getChatEntityList();
                    }
                    if (!TextUtils.isEmpty(hostMember.getHeadImagePath())) {
                        Picasso.with(PlayBackActivity.this).load(hostMember.getHeadImagePath())
                                .placeholder(R.drawable.channel_bg)
                                .into(hostHead);
                    }
                    mPopulatorNum.setText(roomBean.getUser().getTotal_popularity() + "");
                    hostHead.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //换成dialog

                            HostDialogFragment memberDialogFragment = HostDialogFragment.newInstance(hostMember);
                            memberDialogFragment.show(getSupportFragmentManager().beginTransaction(), "show_host");

//                    Intent viewHostIntent = new Intent();
//                    viewHostIntent.setClass(AvActivity.this, StarActivity.class);
//                    viewHostIntent.putExtra(StarActivity.USER_ID, hostMember.getUserPhone());
//                    startActivity(viewHostIntent);
                        }
                    });

                }
            }

            @Override
            public void failure(RetrofitError error) {

            }
        });
    }

    //向用户服务器获取成员信息
    private void getMemberInfo() {
        //TODO 暂时使用测试房间 11
        XLApplication.getInstance().getRestClient().getRoomUsers(mRoomId + "", "online", new Callback<UserBean[]>() {
            @Override
            public void success(UserBean[] userBeans, Response response) {
                page=page+1;
                try {
                    ZhiboUserListResponse zhiboUserListResponse = GsonUtil.fromJson(Util.inputStream2String(response.getBody().in()), ZhiboUserListResponse.class);
                    mUserCount.setText(zhiboUserListResponse.getTotal_count() + "");
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {

                }

                mMemberList.clear();
                String userId = PreferencesStorageUtil.getUserId(PlayBackActivity.this);
//                //添加自己
//                if (!Constants.isCreater) {
//                    MemberInfo memberInfo = new MemberInfo();
//                    memberInfo.setUserPhone(userId);
//                    memberInfo.setHeadImagePath(PreferencesStorageUtil.getUserBean(PlayBackActivity.this).getAvatar());
//                    memberInfo.setUserName(PreferencesStorageUtil.getUserBean(PlayBackActivity.this).getNickname());
//                    memberInfo.setUserDescribe(PreferencesStorageUtil.getUserBean(PlayBackActivity.this).getDescription());
//                    mMemberList.add(memberInfo);
//                }

                if (userBeans != null) {
                    for (UserBean userBean : userBeans) {
                        if (!userBean.getId().equals(userId)) {
                            MemberInfo member = new MemberInfo(userBean.getId() + "", userBean.getNickname(), userBean.getAvatar(), userBean.getDescription());
                            mMemberList.add(member);
                        }
                    }
                    mNormalMemberList = copyToNormalMember();
                    mHandler.sendEmptyMessage(UPDAT_MEMBER);
                }

                if (hostMember != null && mMemberList != null && mMemberList.size() > 0) {
                    getChatEntityList();
                }
            }

            @Override
            public void failure(RetrofitError error) {

            }
        });
    }

    public ArrayList<MemberInfo> copyToNormalMember() {
        mNormalMemberList = new ArrayList<MemberInfo>();
        for (MemberInfo member : mMemberList) {
            mNormalMemberList.add(member);
        }
        return mNormalMemberList;
    }

    private void updateMemberView() {
//        if (mMemberListDialog != null)
//            mMemberListDialog.refreshMemberData(mNormalMemberList);
        mMemberListAdapter.refreshMemberData(mNormalMemberList);
//        mUserCount.setText("" + mMemberList.size());
    }


}
